﻿using System;
using System.Configuration;
using System.Data;
using Module.Core.DAO;
using Module.Core.EntitiesInfo;
using Module.Common.Models;

namespace Module.Core.BusinessLogic.CmsContents
   
{
    public class CMSContentsBL
	{
		/// <summary>
		/// Saves a record to the CMS_Contents table.
		/// </summary>
		public static int Insert(CMSContentsInfo cMSContentsInfo)
		{
			try
			{
                return new CMSContentsDAO().Insert(cMSContentsInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

		/// <summary>
		/// Saves a record to the CMS_Contents table.
		/// </summary>
        public static void Update(CMSContentsInfo cMSContentsInfo)
		{
			try
			{
				new CMSContentsDAO().Update(cMSContentsInfo);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

		/// <summary>
		/// Delete a record from the CMS_Contents table.
		/// </summary>
        public static void Delete(int contentID)
		{
			try
			{
				new CMSContentsDAO().Delete(contentID);
			}
			catch (Exception ex)
			{
				throw;
			}

		}

        public static void UpdateStatus(string contentID, int check)
        {
            try
            {
                new CMSContentsDAO().UpdateStatus(contentID, check);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
		/// <summary>
		/// Selects a single record from the CMS_Contents table.
		/// </summary>
        public static CMSContentsInfo Select(int contentID)
		{
			try
			{
				return new CMSContentsDAO().Select(contentID);
			}
			catch (Exception ex)
			{
				throw;
			}

		}
        public static DataTable SelectFollowZone(int ZoneId)
        {
            try
            {
                return new CMSContentsDAO().SelectFolowZoneId(ZoneId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static CHRTList<CMSContentsInfo> SelectNewTop(int ZoneId)
        {
            try
            {
                return new CMSContentsDAO().SelectNewTop(ZoneId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public static CHRTList<CMSContentsInfo> SelectNew_NoiBat(int ZoneId)
        {
            try
            {
                return new CMSContentsDAO().SelectNewNoiBat(ZoneId);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static DataTable SelectAll(int status)
        {
            try
            {
                return new CMSContentsDAO().SelectAll(status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        public static DataSet PhanTrangTintuc(int currPage, int recodperPage, int pageSize, string link,int status)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new CMSContentsDAO().PhanTrangTintuc(currPage, recodperPage, pageSize, link,status);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        public static DataTable SelectTop5(int status, string showtype)
        {
            try
            {
                return new CMSContentsDAO().SelectTop5(status,showtype);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        public static CMSContentsInfo DetailsNews(int contentID)
        {
            try
            {
                return new CMSContentsDAO().DetailsNews(contentID);
            }
            catch (Exception)
            {
            }
            return null;
        }

        public static CMSContentsInfo SelectFollowKeywors(string keyContents, int status)
        {
            try
            {
                return new CMSContentsDAO().SelectFollowKeywors(keyContents, status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

		/// <summary>
		/// Selects all records from the CMS_Contents table.
		/// </summary>
        public static DataTable SelectSearchAll(int status, int lang, int zoneId, string keyword, int createBy, System.DateTime startDate, System.DateTime endDate, int from, int to)
		{
			try
			{
                return new CMSContentsDAO().SelectSearchAll( status,  lang,  zoneId,  keyword,  createBy, startDate,  endDate,  from,  to);
			}
			catch (Exception ex)
			{
				throw;
			}

		}
        public static int GetCountContent(int status, int lang, int zoneId, string keyword, int createBy, DateTime startDate,
	                     DateTime endDate)
        {
            try
            {
                return new CMSContentsDAO().GetCountContent(status, lang, zoneId, keyword, createBy, startDate, endDate);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        // lấy những bài viết theo zoneId
        public static void GetContentZoneId(string fileNameXML, string pathWriteXML, int lang, int topN, int zoneID, int status, string showType)
        {
            try
            {
                new CMSContentsDAO().GetContentZoneId(fileNameXML, pathWriteXML, lang, topN, zoneID, status, showType);
            }
            catch (Exception)
            {

                throw;
            }
        }

        //Lấy những bài viết mới nhất,tin nổi bật,tin nóng...
        public static void GetContentTypeLates(string fileNameXML, string pathWriteXML, int lang, int topN, int zoneID, int status, string showType, int type)
        {
            try
            {
                new CMSContentsDAO().GetContentTypeLates(fileNameXML, pathWriteXML, lang, topN, zoneID, status, showType, type);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// Hiển thị bài viết theo chuyên mục, bài viết nổi bật, hot,....
        /// </summary>
        /// <param name="lang">Ngôn ngữ:tiếng việt=1,tiếng anh =2</param>
        /// <param name="topN">Số bản ghi cần lấy</param>
        /// <param name="zoneID">Lấy theo chuyên mục</param>
        /// <param name="status">=5 hiển thị</param>
        /// <param name="showType">lấy theo bài viết nổi bật, hot:showType= 2,showType= 4,showType= 8,showType= 18</param>
        /// <param name="type">type =1 hoặc type =2</param>
        /// <returns></returns>
        public static DataTable GetContentTypeLates(int lang, int topN, int zoneID, int status, string showType, int type)
        {
            try
            {
               return new CMSContentsDAO().GetContentTypeLates( lang, topN, zoneID, status, showType, type);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public static void GetContentDetails(string fileNameXML, string pathWriteXML, int lang, int contentId)
        {
            try
            {
                new CMSContentsDAO().GetContentDetails(fileNameXML, pathWriteXML,lang,contentId);
            }
            catch (Exception)
            {

                throw; 
            }
        }
        public static CMSContentsInfo GetNewsContent(string KeyContents, int status)
        {
            try
            {
                return new CMSContentsDAO().GetContentDetails(KeyContents, status);
            }

            catch (Exception)
            {

                throw;
            }
        }
	}
}
